package com.aliyun.messagemgt.controller;

import com.aliyun.messagemgt.application.service.MsgSourceService;
import com.aliyun.messagemgt.application.service.OperateLogService;
import com.aliyun.messagemgt.dto.MsgAdd;
import com.aliyun.messagemgt.dto.query.MsgQuery;
import com.aliyun.messagemgt.dto.vo.MsgSourceVO;
import com.aliyun.messagemgt.web.controller.MsgSourceController;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.ArrayList;

/**
 * @author wenyaxin
 * @date 2020/12/2
 */
@RunWith(MockitoJUnitRunner.class)
public class MsgSourceControllerTest {

    @InjectMocks
    private MsgSourceController msgSourceController;

    @Mock
    private MsgSourceService msgSourceService;

    @Mock
    private OperateLogService operateLogService;

    @Test
    public void msgSourceAddTest(){
        Mockito.when(msgSourceService.addMsgSource(Mockito.any())).thenReturn(1);
        Mockito.when(operateLogService.insertOperateLog(Mockito.any())).thenReturn(1);
        msgSourceController.msgSourceAdd(createMsgAdd());
    }

    @Test
    public void msgSourceSaveTest(){
        MsgSourceVO msgSourceVO = new MsgSourceVO();
        msgSourceVO.setSourceName("1");
        Mockito.when(msgSourceService.msgSourceDetail(Mockito.any())).thenReturn(msgSourceVO);
        Mockito.when(msgSourceService.saveMsgSource(Mockito.any())).thenReturn(1);
        Mockito.when(operateLogService.insertOperateLog(Mockito.any())).thenReturn(1);
        msgSourceController.msgSourceSave(createMsgAdd());
    }

//    @Test
//    public void msgSourceOffLineTest(){
//        MsgSourceVO msgSourceVO = new MsgSourceVO();
//        msgSourceVO.setSourceName("1");
//        Mockito.when(msgSourceService.msgSourceDetail(Mockito.any())).thenReturn(msgSourceVO);
//        Mockito.when(msgSourceService.modMsgSource(Mockito.any())).thenReturn(1);
//        Mockito.when(operateLogService.insertOperateLog(Mockito.any())).thenReturn(1);
//        msgSourceController.msgSourceOffLine(createMsgAdd());
//    }

    @Test
    public void msgSourceListTest(){
        Mockito.when(msgSourceService.listMsgSource(Mockito.any())).thenReturn(new Page<>());
        msgSourceController.msgSourceList(new MsgQuery());
    }

    @Test
    public void msgSourceDetailTest(){
        Mockito.when(msgSourceService.msgSourceDetail(Mockito.any())).thenReturn(new MsgSourceVO());
        msgSourceController.msgSourceDetail(new MsgQuery());
    }

    @Test
    public void msgSourceMessageListTest(){
        Mockito.when(msgSourceService.queryMsgList(Mockito.any())).thenReturn(new PageInfo<>());
        msgSourceController.msgSourceMessageList(new MsgQuery());
    }

    @Test
    public void msgSourceMessageOwnerDeptTest(){
        Mockito.when(msgSourceService.listOwnerDeptForMessage(Mockito.any())).thenReturn(new ArrayList<>());
        msgSourceController.msgSourceMessageOwnerDept(new MsgQuery());
    }

    @Test
    public void msgSourceOwnerDeptTest(){
        Mockito.when(msgSourceService.listOwnerDept(Mockito.any())).thenReturn(new ArrayList<>());
        msgSourceController.msgSourceOwnerDept(new MsgQuery());
    }

    @Test
    public void listMessageTypesTest(){
        Mockito.when(msgSourceService.listMessageTypes()).thenReturn(new ArrayList<>());
        msgSourceController.listMessageTypes(new MsgQuery());
    }

    @Test
    public void deleteMsgSourceTest(){
        MsgSourceVO msgSourceVO = new MsgSourceVO();
        msgSourceVO.setSourceName("1");
        Mockito.when(msgSourceService.msgSourceDetail(Mockito.any())).thenReturn(msgSourceVO);
        Mockito.when(msgSourceService.deleteMsgSource(Mockito.any())).thenReturn(1);
        Mockito.when(operateLogService.insertOperateLog(Mockito.any())).thenReturn(1);
        msgSourceController.deleteMsgSource(createMsgQuery());
    }

    private MsgAdd createMsgAdd(){
        MsgAdd msgAdd = new MsgAdd();
        msgAdd.setUserId("1");
        msgAdd.setUserName("1");
        msgAdd.setDepartment("1");
        msgAdd.setDepartmentName("1");
        msgAdd.setMsgSourceId(1L);
        msgAdd.setSourceName("1");
        return msgAdd;
    }

    private MsgQuery createMsgQuery(){
        MsgQuery msgQuery = new MsgQuery();
        msgQuery.setUserId("1");
        msgQuery.setUserName("1");
        msgQuery.setDepartment("1");
        msgQuery.setDepartmentName("1");
        msgQuery.setMsgSourceId(1L);
        msgQuery.setSourceName("1");
        return msgQuery;
    }
}
